package main

import (
	"fmt"
	"github.com/redmask-hb/GoSimplePrint/goPrint"
	"os"
	"time"
)

var (
	fileConf Resource
)

func main() {
	fileConf = Resource{Config: struct {LoginUrl, Username, Password string}{
		LoginUrl: `https://x.x.x.x:xxxx/zabbix/api_jsonrpc.php`,
		Username: `xxxxx`,
		Password: `xxxxxx`,
	}, OutDirConf: []Group{
		{GroupName: "CPE-X86", Path: `.\`},
		{GroupName: "PCDN", Path: `.\`},
		{GroupName: "国内POP组", Path: `.\`},
		{GroupName: "海外POP组", Path: `.\`},
		{GroupName: "CN2-POP组", Path: `.\`},
	}}

	bar:=goPrint.NewBar(3)
	myZabbix := NewObj(fileConf.Config.LoginUrl, fileConf.Config.Username, fileConf.Config.Password, bar)
	defer func(){err := myZabbix.Close(); if err != nil {fmt.Println(err);return}}()
	myZabbix.flushHostMap(bar)
	Evnts := make(map[string]int)
	EvntsClock := make(map[string][]string)
	myZabbix.getEvents(&Evnts, &EvntsClock, bar)
	dir := fileConf.OutDirConf[0].Path+fmt.Sprintf("%s", time.Now().Format("2006-01-02-15-04-05"))
	for _, group := range fileConf.OutDirConf {
			itemInfo := make(map[string]*hostItem)
			myZabbix.handleData(myZabbix.getHostItem(myZabbix.getGroupID(group.GroupName)), &itemInfo, &Evnts, group.GroupName, &EvntsClock)
			if _, err := os.Stat(dir); os.IsNotExist(err) {
				os.MkdirAll(dir, os.ModePerm)
			}
			CreateExcelFile(dir, group.GroupName, &itemInfo)
	}
}